package com.lantu.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lantu.common.vo.RResult;
import com.lantu.sys.entity.Discipline;
import com.lantu.sys.service.DisciplineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/jiaowu")
@CrossOrigin
@Slf4j
public class DisciplineController {

    @Autowired
    private DisciplineService disciplineService;

    //显示学科列表
    @GetMapping("/allxueke/{pageNo}/{pageSize}")
    public RResult getAllXueke(@PathVariable("pageNo") Integer pageNo,
                               @PathVariable("pageSize") Integer pageSize,
                               Discipline discipline){
        Page<Discipline> pageParam = new Page<>(pageNo,pageSize);
        IPage<Discipline> xuekePage = disciplineService.getxueke(pageParam,discipline);
        return RResult.ok(xuekePage);
    }

    //实现回显功能
    @GetMapping("/xueke/{id}")
    public RResult<Discipline> getById(@PathVariable("id") Integer id){
        QueryWrapper<Discipline> queryWrapper = new QueryWrapper<>();
        Discipline id1 = disciplineService.getOne(queryWrapper.eq("id", id));

        return RResult.ok(id1);
    }

    // 新增或者修改操作
    @PostMapping("/addOrUpdateXueke")
    public RResult addOrUpdateXueke(@RequestBody Discipline discipline){
        disciplineService.saveOrUpdate(discipline);
        return RResult.ok();
    }


    //通过id进行删除
    @DeleteMapping("/delete/{id}")
    public RResult getBId(@PathVariable("id") Integer id){
        disciplineService.removeById(id);
        return RResult.ok();
    }

}
